@echo off
setlocal
set logfile=%StartupLogs%\RunRulesConfigurator.log

echo %date% %time% >> %logfile% 2>&1
echo %cd% >> %logfile% 2>&1

:: Remove trailing backslash
IF "%ConfigCache:~-1%"=="\" SET ConfigCache=%ConfigCache:~,-1%

"RulesConfigurator.exe" "%ConfigLocation%" "%ConfigCache%">> %logfile% 2>&1
if %ERRORLEVEL% EQU 0 goto :Schedule
exit /b %ERRORLEVEL%
goto :eof

:Schedule
schtasks /Create /F /RU "NT AUTHORITY\SYSTEM" /SC DAILY /RI 1 /DU 24:00 /TN RulesConfigurator /TR "'%cd%\RulesConfigurator.exe' '%ConfigLocation%'" >> %logfile% 2>&1
exit /b 0

